import type {
  GroupAddFavoriteForm,
  GroupForm,
  GroupImportForm,
  GroupMergeForm,
  GroupQuery,
  GroupTransferForm,
  GroupVO,
} from './model';

import type { ID, IDS, PageResult } from '#/api/common';

import { commonExport, ContentTypeEnum } from '#/api/helper';
import { requestClient } from '#/api/request';

/**
 * 分页查询参观团列表
 * @param params
 * @returns 参观团列表
 */
export function groupPage(params?: GroupQuery) {
  return requestClient.get<PageResult<GroupVO>>('/register/group/page', {
    params,
  });
}

/**
 * 查询参观团列表
 * @param params
 * @returns 参观团列表
 */
export function groupList(params?: GroupQuery) {
  return requestClient.get<GroupVO[]>('/register/group/list', { params });
}

/**
 * 导出参观团列表
 * @param params
 * @returns 参观团列表
 */
export function groupExport(params?: GroupQuery) {
  return commonExport('/register/group/export', params ?? {});
}

/**
 * 查询参观团详情
 * @param id id
 * @returns 参观团详情
 */
export function groupInfo(id: ID) {
  return requestClient.get<GroupVO>(`/register/group/${id}`);
}

/**
 * 新增参观团
 * @param data
 * @returns void
 */
export function groupAdd(data: GroupForm) {
  return requestClient.postWithMsg<void>('/register/group', data);
}

/**
 * 更新参观团
 * @param data
 * @returns void
 */
export function groupUpdate(data: GroupForm) {
  return requestClient.putWithMsg<void>('/register/group', data);
}

/**
 * 更新参观团状态
 * @param data
 * @returns void
 */
export function groupUpdateStatus(data: GroupForm) {
  return requestClient.putWithMsg<void>(`/register/group/changeStatus`, data);
}

/**
 * 删除参观团
 * @param id id
 * @returns void
 */
export function groupRemove(id: ID | IDS) {
  return requestClient.deleteWithMsg<void>(`/register/group/${id}`);
}

/**
 * 转移参观团至其他跟进人
 * @param data
 */
export function groupTransferFollowUp(data: GroupTransferForm) {
  return requestClient.postWithMsg<void>(
    '/register/group/transferFollowUp',
    data,
  );
}

/**
 * 参观团合并
 * @param data
 */
export function groupMerge(data: GroupMergeForm) {
  return requestClient.postWithMsg<void>('/register/group/merge', data);
}

/**
 * 参观团导入
 * @param data
 * @returns void
 */
export function groupImport(data: GroupImportForm) {
  return requestClient.postWithMsg<void>('/register/group/importExcel', data, {
    headers: {
      'Content-Type': ContentTypeEnum.FORM_DATA,
    },
    isTransformResponse: false,
  });
}

/**
 * 下载参观团导入模板
 * @returns blob
 */
export function groupDownloadImportTemplate(params?: GroupQuery) {
  return commonExport('/register/group/importTemplate', params ?? {});
}

/**
 * 批量添加参观团到收藏夹
 * @param data
 */
export function groupAddToFavorite(data: GroupAddFavoriteForm) {
  return requestClient.postWithMsg<void>(`/register/group/addFavorite`, data);
}

/**
 * 更新参观团主联系人
 * @param data
 */
export function groupUpdateMaster(data: { id: ID; registerId: ID }) {
  return requestClient.putWithMsg<void>(`/register/group/updateMaster`, data);
}

/**
 * 参观团加入人员
 * @param data
 */
export function groupAddMember(data: GroupAddFavoriteForm) {
  return requestClient.putWithMsg<void>(`/register/group/addMember`, data);
}

/**
 * 转移人员至其他参观团
 * @param data
 */
export function groupATransferMember(data: GroupAddFavoriteForm) {
  return requestClient.putWithMsg<void>(`/register/group/moveMember`, data);
}

/**
 * 参观团移除人员
 * @param registerId
 */
export function groupRemoveMember(registerId: ID) {
  return requestClient.putWithMsg<void>(
    `/register/group/removeMember/${registerId}`,
  );
}

/**
 * 下载参观团入场码
 * @param id
 */
export function groupDownloadEntryCode(id: ID) {
  return requestClient.get<null | string>(`/register/group/downloadCode/${id}`);
}
